import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { DescItem } from '/@/components/Description/index';
import { PicBoolean } from '/@/components/PicBoolean/index';
import { FullSrcPic } from '/@/components/FullSrcPic/index';
import { CheckList } from '/@/components/CheckList/index';
import { StatusIcon } from '/@/components/StatusIcon/index';
import { ImgIcon } from '/@/components/ImgIcon/index';
import { Pczt } from '/@/components/Pczt/index';
import { defineComponent, h } from 'vue';
import { Tag } from 'ant-design-vue';

export function getMergeBasicColumns(): BasicColumn[] {
  return [
    {
      title: '排查时间',
      dataIndex: 'pcsj',
    },
    {
      title: '隐患状态',
      width: 200,
      dataIndex: 'pczt',
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: parseInt(value),
        });
      },
    },
    {
      title: '隐患数量',
      width: 250,
      dataIndex: 'yhnum',
    },
    {
      title: '整改数量',
      dataIndex: 'zgnum',
    },
    {
      title: '灭火器数量',
      width: 150,
      dataIndex: 'mhqsl',
    },
    {
      title: '防烟逃生面罩',
      width: 150,
      dataIndex: 'fytsmz',
    },
    {
      title: '悬挂固定警示标牌',
      width: 200,
      dataIndex: 'xggdjsbp',
    },
    {
      title: '房屋简易喷头数量',
      width: 200,
      dataIndex: 'jzsyjyplmhxts',
    },
    {
      title: '房屋烟感报警器数量',
      width: 200,
      dataIndex: 'jzszlwxdlgybjqs',
    },
    {
      title: '房屋首层现有安全出口的数量',
      width: 200,
      dataIndex: 'jzscxyaqcksl',
    },
    {
      title: '房屋现有疏散楼梯的数量',
      width: 200,
      dataIndex: 'jzxyssltsl',
    },
  ];
}

export function getHistoryBasicColumns(): BasicColumn[] {
  return [
    {
      title: '排查状态',
      width: 200,
      dataIndex: 'pczt',
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    },
    {
      title: '隐患数量',
      width: 200,
      dataIndex: 'numyhwtXf',
    },

    {
      title: '核查意见',
      width: 200,
      dataIndex: 'checkMind',
    }, 
    {
      title: '排查时间',
      width: 200,
      dataIndex: 'createOn',
    },
  ];
}

export function getResidentBasicColumns(): BasicColumn[] {
  return [
    {
      title: '排查状态',
      dataIndex: 'pczt',
      width: 200,
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    },
    {
      title: '场所名称',
      dataIndex: 'placeName',
      width: 150,
    },
    {
      title: '场所位置',
      dataIndex: 'location',
    },
    {
      title: '户主姓名',
      width: 150,
      dataIndex: 'householder',
    },
    {
      title: '联系方式',
      width: 150,
      dataIndex: 'contact',
    },
    {
      title: '可居住人口数',
      width: 150,
      dataIndex: 'maxPopulation',
    },
    {
      title: '建筑层数',
      width: 150,
      dataIndex: 'buildingFloors',
    },
    {
      title: '出租房间数',
      width: 150,
      dataIndex: 'leaseRooms',
    },
    {
      title: '出租房间居住人数',
      width: 150,
      dataIndex: 'leaseRoomPeoples',
    },
    {
      title: '风险评估',
      dataIndex: 'level',
      width: 150,
      slots: { customRender: 'renderLevel' },
    },
    {
      title: '排查时间',
      width: 200,
      dataIndex: 'createOn',
    },
    {
      title: '修改时间',
      width: 200,
      dataIndex: 'modifiedOn',
    },
  ];
}

export function getCommercialBasicColumns(): BasicColumn[] {
  return [
    {
      title: '排查状态',
      dataIndex: 'pczt',
      width: 200,
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    },
    {
      title: '场所名称',
      dataIndex: 'placeName',
      width: 150,
    },
    {
      title: '场所位置',
      dataIndex: 'location',
    },
    {
      title: '联系方式',
      width: 150,
      dataIndex: 'contact',
    },
    {
      title: '经营面积',
      width: 150,
      dataIndex: 'businessArea',
    },
    {
      title: '具体用途',
      dataIndex: 'specificPurpose',
      width: 450,
      customRender: ({ value }) => {
        return h(CheckList, {
          checkVal: value,
        });
      },
    },
    {
      title: '排查时间',
      width: 200,
      dataIndex: 'createOn',
    },
    {
      title: '修改时间',
      width: 200,
      dataIndex: 'modifiedOn',
    },
  ];
}

export function getFwDetailColumns(chk: boolean): DescItem[] {
  return [
    {
      label: '隐患状态',
      field: 'pczt',
      render: (curVal) => {
        return h(Pczt, {
          pcztVal: parseInt(curVal),
        });
      },
    },
    {
      label: '自查时间',
      field: 'pcsj',
    },
    {
      label: '户主姓名',
      field: 'hzxm',
    },
    {
      label: '房屋编号',
      field: 'fwbh',
    },
    {
      label: '总居住人数(人)',
      field: 'jzrks',
    },
    {
      label: '租住人数(人)',
      field: 'zzrs',
    },
    {
      label: '房屋层数(层)',
      field: 'cs',
    },
    {
      label: '房间数量(个)',
      field: 'fjsl',
    },
    {
      label: '出租房间数量(个)',
      field: 'jzfjs',
    },
    {
      label: '房屋首层现有安全出口的数量 (个)',
      field: 'jzscxyaqcksl',
    },
    {
      label: '房屋现有疏散楼梯的数量(个)',
      field: 'jzxyssltsl',
    },
    {
      label: '房屋首层面积 (平方米)',
      field: 'jzscmj',
    },
    {
      label: '窗口防护网、广告牌、铁栅栏数量 (个)',
      field: 'ckfhwggptzlsl',
    },
    {
      label: '本房屋居住人员的电动自行车数量(辆)',
      field: 'bdfwjzrydddzxcsl',
    },
    {
      label: '灭火器数量(个)',
      field: 'mhqsl',
    },
    {
      label: '防烟逃生面罩数量(套）',
      field: 'fytsmz',
    },
    {
      label: '悬挂固定警示标牌数量(张)',
      field: 'xggdjsbp',
    },
    {
      label: '房屋简易喷头数量(个)',
      field: 'jzsyjyplmhxts',
    },
    {
      label: '房屋烟感报警器数量(个)',
      field: 'jzszlwxdlgybjqs',
    },
    {
      label: '屋顶、围护结构、房间隔墙使用易燃可燃夹芯彩钢板搭建',
      field: 'wdwhjgfjgqsyyrkrgbdj',
    },
    {
      label: '疏散通道使用易燃可燃材料装修',
      field: 'sstdsyyrkrclzx',
    },
    {
      label: '供人员疏散的场院、内院、天井设置不利于烟气扩散的顶棚、雨棚等',
      field: 'gryssdcsszblyyqksddp',
    },
    {
      label: '除居住外是否存在其他经营业态',
      field: 'cjzwqtjyytmsg',
    },
    {
      label: '建设人员疏散通道',
      field: 'jsrysstd',
    },
  ];
}

export function getYhDetailColumns(chk: boolean): DescItem[] {
  return [
    {
      label: '电动自行车、电动平衡车及其蓄电池在室内及安全出口处停放、充电',
      field: 'use_electric_bicycle',
      render: (curVal, data) => {
        if (
          data['use_electric_bicycle_photo'] != '[""]' ||
          data['use_electric_bicycle_photo'] != ''
        ) {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['use_electric_bicycle_photo'],
          });
        }
      },
    },
    {
      label: '在公共区域、租住房间内、地下室使用瓶装液化石油气  ',
      field: 'use_bottled_liquefied_gas',
      render: (curVal, data) => {
        if (
          data['use_bottled_liquefied_gas_photo'] != '[""]' ||
          data['use_bottled_liquefied_gas_photo'] != ''
        ) {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['use_bottled_liquefied_gas_photo'],
          });
        }
      },
    },
    {
      label: '疏散走道、楼梯间、安全出口处堆放物品影响人员疏散',
      field: 'use_stacked_items',
      render: (curVal, data) => {
        if (data['use_stacked_items_photo'] != '[""]' || data['use_stacked_items_photo'] != '') {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['use_stacked_items_photo'],
          });
        }
      },
    },
    {
      label: '私拉乱接电线',
      field: 'slljdx',
      render: (curVal, data) => {
        if (data['slljdx_photo'] != '[""]' || data['slljdx_photo'] != '') {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['slljdx_photo'],
          });
        }
      },
    },
    {
      label: '灭火器未保持完好有效',
      field: 'mhqwbcwhyx',
      render: (curVal, data) => {
        if (data['mhqwbcwhyx_photo'] != '[""]' || data['mhqwbcwhyx_photo'] != '') {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['mhqwbcwhyx_photo'],
          });
        }
      },
    },
    {
      label: '简易喷淋灭火系统未保持完好有效',
      field: 'jyplmhxtwbcwhyx',
      render: (curVal, data) => {
        if (data['jyplmhxtwbcwhyx_photo'] != '[""]' || data['jyplmhxtwbcwhyx_photo'] != '') {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['jyplmhxtwbcwhyx_photo'],
          });
       }
      },
    },
    {
      label: '烟感报警器未保持完好有效',
      field: 'ygbjwfwhyx',
      render: (curVal, data) => {
        if (data['ygbjwfwhyx_photo'] != '[""]' || data['jyplmhxtwbcwhyx_photo'] != '') {
          return h(PicBoolean, {
            bVal: curVal,
            picList: data['ygbjwfwhyx_photo'],
          });
        }
      },
    },
    {
      label: '户主签字',
      field: 'sign',
      render: (curVal) => {
        return h(ImgIcon, {
          imgVal: curVal,
        });
      },
    },
  ];
}

export const searchFormSchema: FormSchema[] = [
  {
    field: 'pczt',
    label: '隐患状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '已排查无隐患', value: 20 },
        { label: '已排查有隐患', value: 21 },
        { label: '未排查', value: 0 },
      ],
      placeholder: '请选择排查状态',
    },
    labelWidth: '5em',
    colProps: { span: 8 },
  },
  // {
  //   field: 'yhly',
  //   label: '隐患来源',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '村民自查', value: 1 },
  //       { label: '村级检查', value: 2 },
  //       { label: '乡镇核查', value: 3 },
  //       { label: '区级督查', value: 4 },
  //     ],
  //     placeholder: '请选择隐患来源',
  //   },
  //   labelWidth: '5em',
  //   colProps: { span: 8 },
  // },
];

export function getBasicShortColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      width: 150,
      dataIndex: 'id',
      sorter: true,
      sortOrder: 'ascend',
    },
  ];
}

export function getMultipleHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}

export function getCustomHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}
const renderContent = ({ text, index }: { text: any; index: number }) => {
  const obj: any = {
    children: text,
    attrs: {},
  };
  if (index === 9) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};
export function getMergeHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 300,
      customRender: renderContent,
    },
  ];
}
export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  const arr: any = [];
  for (let index = 0; index < itemNumber; index++) {
    arr.push({
      field: `field${index}`,
      label: `字段${index}`,
      component: 'Input',
      colProps: {
        xl: 12,
        xxl: 8,
      },
    });
  }
  return arr;
};
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      ...getAdvanceSchema(5),
      {
        field: `field11`,
        label: `Slot示例`,
        component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}
